local hanta = fk.CreateSkill {
  name = "lingling__hanta",
}

Fk:loadTranslationTable {
  ["lingling__hanta"] = "酣踏",
  [":lingling__hanta"] = "一名角色回合开始时，你可以失去1点体力，视为对其使用【杀】，若未造成伤害，其将一张牌当【酒】使用，" ..
      "若造成伤害，你可以将一张牌当【桃】使用，且若你与其的距离为1，你先摸一张牌。",

  ["#lingling__hanta-invoke"] = "酣踏：你可以失去1点体力，视为对 %dest 使用【杀】",
  ["#lingling__hanta-analeptic"] = "酣踏：请将一张牌当【酒】使用",
  ["#lingling__hanta-peach"] = "酣踏：你可以将一张牌当【桃】使用",
}

hanta:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hanta.name) and player.hp > 0 and target and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = hanta.name,
      prompt = "#lingling__hanta-invoke::" .. target.id,
    }) then
      event:setCostData(self, { tos = { target } })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, hanta.name)
    if target.dead then return end
    local use = room:useVirtualCard("slash", nil, player, target, hanta.name, true)
    if use and use.damageDealt then
      if not player.dead then
        if use.extra_data and use.extra_data.lingling__hanta_heck then
          player:drawCards(1, hanta.name)
        end
        if not player.dead then
          room:askToUseVirtualCard(player, {
            name = "peach",
            skill_name = hanta.name,
            prompt = "#lingling__hanta-peach",
            cancelable = true,
            card_filter = {
              n = 1,
            },
          })
        end
      end
    elseif not target.dead then
      room:askToUseVirtualCard(target, {
        name = "analeptic",
        skill_name = hanta.name,
        prompt = "#lingling__hanta-analeptic",
        cancelable = false,
        card_filter = {
          n = 1,
        },
        extra_data = {
          bypass_times = true,
          extraUse = true,
        }
      })
    end
  end,
})

hanta:addEffect(fk.DamageCaused, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:distanceTo(data.to) == 1 and data.card and
      table.contains(data.card.skillNames, hanta.name) and
      player.room.logic:damageByCardEffect()
  end,
  on_refresh = function(self, event, target, player, data)
    local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if use_event and use_event.data.card == data.card then
      use_event.data.extra_data = data.extra_data or {}
      use_event.data.extra_data.lingling__hanta_heck = true
    end
  end,
})

return hanta
